package af.Action;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

import af.Class.Responsable;
import af.Form.ResponsableForm;


public class ResponsableAction extends DispatchAction{

	public ActionForward ListaResponsables(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        Responsable resp = new Responsable();
        //HttpSession session = request.getSession();

        //traigo el listado de todos los responsables
        request.getSession().setAttribute("grResponsable", resp.ListaResponsable());
        

        return mapping.findForward("listar");
    }

	public ActionForward NuevoResponsable(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
		//obtengo el formulario
		ResponsableForm frm = (ResponsableForm) form;
		//seteo que el responsable es nuevo
		frm.setNuevo("S");
		return mapping.findForward("nuevo");
	}
	public ActionForward ModificarResponsable(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
		   //recibo el codigo del activo
			String cod = request.getParameter("codigo");
			//creo un nuevo responsable
			Responsable resp = new Responsable();
			//tomo el formulario
			ResponsableForm frm = (ResponsableForm) form;
			//estipulo que no es nuevo si no que una modificacion
			frm.setNuevo("M");
			//seteo el codigo
			frm.setCodigo(cod);
			//traigo los datos del responsable para mostrarlos en la vista
			frm = resp.TraeResponsable(frm);
						
		return mapping.findForward("modificar");
	}
	
	public ActionForward EliminarResponsable(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
			//traigo el codigo
			String cod = request.getParameter("codigo");
			
			Responsable resp = new Responsable();
			//traigo el fromulario
			ResponsableForm frm = (ResponsableForm) form;
			//seteo el codigo del responsable a eliminar
			frm.setCodigo(cod);
			//elimino el responsable
			resp.EliminaResponsable(frm);
				
						
			return mapping.findForward("eliminar");
	}
	
}



